package org.hxyjs.controller;

import org.hxyjs.dto.DTO;
import org.hxyjs.entity.Information;
import org.hxyjs.page.PageInfo;
import org.hxyjs.service.InformationService;
import org.springframework.cloud.openfeign.SpringQueryMap;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;

@CrossOrigin
@Controller //@Controller注解是用spring容器生成 对象 默认对象名 informationController
@RequestMapping("/informationController") //@RequestMapping 用户请求查找该资源使用的名字 网名 默认  /informationController
public class InformationController {
	@Resource
    InformationService informationService;

	@GetMapping("/getAllinformation")
	@ResponseBody //把方法的返回值按json转换之后 输出到浏览器
    public DTO<Information> getAllInformation() throws Exception{
    	System.out.println("查询全部咨询");
    	return informationService.getAllInformations();
    }

	@PostMapping("/addinformation")
	@ResponseBody
	public DTO<Information> addInformation(@RequestBody Information information) throws Exception{//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println("增加咨询成功");
		return informationService.addInformation(information);
	}
	@DeleteMapping("/deleteinformation/{ino}")
	@ResponseBody
    public DTO<Information> deleteInformationByIno(@RequestBody @PathVariable("ino") String ino) throws Exception{//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
    	System.out.println(ino+"删除咨询成功");
    	return informationService.deleteInformationByIno(ino);
    }

	@GetMapping("/informationBy/{ino}")
	@ResponseBody
	public DTO<Information> getInformationByIno(@PathVariable("ino") String ino) throws Exception{//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println(ino+"根据主键查询咨询成功");
		return informationService.getInformationByIno(ino);
	}

	@PatchMapping("/updateinformation")
	@ResponseBody
	public DTO<Information> updateInformationByIno(@RequestBody Information information) throws Exception{//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println("修改咨询成功");
		System.out.println(information);
		return informationService.updateInformationByIno(information);
	}

	@RequestMapping("/information/pageInfo")
	@ResponseBody
	public DTO<Information> getInformationByPage(@SpringQueryMap PageInfo pageInfo) throws Exception{//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println("查询分页");
		return informationService.getInformationByPage(pageInfo);
	}

}
